<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>个人信息</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/login.css">
    <style>
        body{
            background-image: url("./image/background_Login.jpg");
            background-size: 100%;
        }
    </style>
</head>
<body>
<!--    导航栏-->
<div class="nav">
    <img src="image/person_Blog.png" alt="">
    <span>我的博客系统</span>
    <div class="spacer"></div>
    <a href="main.html">主页</a>
    <a href="edit.html">写博客</a>
</div>
<div class="login-container">
    <div class="login-dialog">
        <h3>个人信息</h3>
        <div class="row">
            <span>用户名*</span>
            <input type="text" id="username">
        </div>
        <div class="row">
            <span>密码*</span>
            <input type="password" id="password">
        </div>
        <div class="row">
            <span>github</span>
            <input type="text" id="github">
        </div>
        <div class="row">
            <input type="submit" id="submit">
        </div>
    </div>
</div>

<script src="jquery.js"></script>
<script src="js/common.js"></script>
<script>
    submitMethod = function(){
        let username = document.querySelector("#username");
        let password = document.querySelector("#password");
        let github = document.querySelector("#github");
        let user = {
            username: username.value,
            password: password.value,
            github: github.value
        }
        $.ajax({
            type: 'post',
            url: 'login' + "?change=yes",
            contentType: 'application/json',
            data: JSON.stringify(user),
            success: function (body) {
                if (body == 'usernameNull'){
                    alert('用户名不能为空!')
                }else if (body == 'passwordNull'){
                    alert('密码不能为空!')
                }else if (body == 'failed'){
                    alert('用户名或密码错误!')
                }else if (body == 'exist'){
                    alert("该用户已经存在!")
                }else if (body == 'success'){
                    location = 'main.html'
                }
                // 清空内容
                username.value = '';
                password.value = '';
            }
        })
    }
    let submit = document.querySelector("#submit");
    submit.onclick = function () {
        submitMethod();
    }
    $('#username').bind('keydown', function (e) {
        // enter键
        if(e.keyCode == 13){
            submitMethod();
        }
    })
    $('#password').bind('keydown', function (e) {
        // enter键
        if(e.keyCode == 13){
            submitMethod();
        }
    })
    $('#github').bind('keydown', function (e) {
        // enter键
        if(e.keyCode == 13){
            submitMethod();
        }
    })
</script>
</body>
</html>